package Server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Main {
    public static ExecutorService executorService;
    public static void main(String[] args) {
        executorService = Executors.newFixedThreadPool(20); // 创建一个固定大小的线程池
        try {
            ServerSocket serverSocket = new ServerSocket(3684);
            System.out.println("服务器正在启动");
            while (true) {
                Socket socket = serverSocket.accept();
                System.out.println("连接到" + socket.getInetAddress() + "的主机");
                Runnable worker = new LoginServer(serverSocket,socket); // 创建一个 Server.LoginServer 实例
                executorService.execute(worker); // 将实例提交到线程池中执行
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}